<?php

namespace Php\Queue;


use Php\Queue\work\Liunx;
use Php\Queue\work\Swoole;
use Php\Queue\work\Win;

class Work
{
	public $queue;
	
	public function __construct(RedisConfig $config)
	{
		$this->queue = new Query($config);
	}
	
	/**
	 * 启动
	 *
	 * @author  chenhuan  2023/1/12
	 * @return void
	 */
	public function start()
	{
		// 环境判断
		if (substr(PHP_OS,0, 3) == 'WIN') {
			$this->win();
		} else {
			$this->Liunx();
		}
	}
	
	public function win()
	{
		// 判断是否开启swoole
		if (extension_loaded('swoole')) {
			$client = new Swoole($this->queue);
		} else {
			$client = new Win($this->queue);
		}
		$client->run();
	}
	
	public function run($argv)
	{
//		if ($argv[1] == 'start') {
			$this->start();
//		} elseif ($argv[1] == 'stop') {
//			$this->stop();
//		} elseif ($argv[1] == 'restart') {
//			$this->stop();
//			$this->start();
//		} else {
//			echo 'param error';
//		}
	}
	
	/**
	 * 停止
	 *
	 * @author  chenhuan  2023/1/12
	 * @return void
	 */
	public function stop()
	{
	
	}
	
	public function Liunx()
	{
		// 判断是否开启swoole
		if (extension_loaded('swoole')) {
			$client = new Swoole($this->queue);
		} else {
			$client = new Liunx($this->queue);
		}
		$client->run();
	}
	
	/**
	 * 重启
	 *
	 * @author  chenhuan  2023/1/12
	 * @return void
	 */
	public function restart()
	{
	
	}
}